package com.wanma.thread;
/**
 * 多线程
 * @author Administrator
 *
 */
public class Demo {

	public static void main(String[] args) {
		DemoThread demoThread = new DemoThread();
		demoThread.start();
		Thread thread = new Thread(new DemoThread1());
		thread.start();
		for (int i = 0; i < 20; i++) {
			System.out.println("Main /n" + i);
		}
		new Thread(new Runnable() {	
			@Override
			public void run() {
				for (int i = 0; i < 20; i++) {
					System.out.println("DemoThread3 /n" + i);
				}
			}
		}).start();
	}
}
class DemoThread extends Thread{
	@Override
	public void run() {
		//设置线程名字
		setName("DemoThread");
		
		for (int i = 0; i < 20; i++) {
			System.out.println("DemoThread  /n" + getId() + "name :"+ getName() + "Id :" + currentThread().getId()  +"-----------"+ i);
		}
	
	}
}
class DemoThread1 implements Runnable{
	@Override
	public void run() {
		for (int i = 0; i < 20; i++) {
			System.out.println("DemoThread1 /n"  + Thread.currentThread().getId() +"----------------"+i);
		}
	}
}


